package com.hot100.mid;


import java.util.Stack;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 最小栈 ，采用空间换时间做法
 * @date 2022/9/4 12:25
 */
public class Demo36 {
    class MinStack {
        Stack<Integer> minStack;


        public MinStack() {
            minStack = new Stack<>();
        }

        public void push(int val) {
            //存两个数，一个是本来应该存的数字，一个是当前栈中最小值
            if (minStack.isEmpty()) {
               minStack.push(val);
               minStack.push(val);
            }else {
                Integer peek = minStack.peek();
                minStack.push(val);
                if(val<peek){
                    minStack.push(val);
                }else {
                    minStack.push(peek);
                }
            }

        }

        public void pop() {
            Integer pop = minStack.pop();
            Integer pop1 = minStack.pop();

        }

        public int top() {
         return    minStack.get(minStack.size()-2);
        }

        public int getMin() {
            return minStack.peek();
        }
    }
}
